package com.zqxq.lottery.cms.controller;

import com.alibaba.fastjson.JSONObject;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.cms.feign.LotteryServerFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 苦智
 * @date 2018/6/22 15:19
 * @description 极光推送
 * @ClassName JPushMsgController
 */
@Api(value = "推送管理",tags = "推送管理")
@RestController
@Slf4j
@RequestMapping("/jPush")
public class JPushController {
    @Autowired
    private LotteryServerFeignClient lotteryServerFeignClient;

    @ApiOperation(value = "极光推送",notes = "极光推送")
    @PostMapping("/pushMsgToUser")
    public Result pushMsgToUser(@ApiParam(value = "推送目标",required = false) @RequestParam(defaultValue = "ALL") String target,
                                @ApiParam(value = "推送标题",required = true) String title,
                                @ApiParam(value = "推送内容",required = true) String content,
                                @ApiParam(value = "推送工具 1：极光推送 2：站内消息") Integer type){
        log.info("极光推送 mobile={},msg={},content={},type={}",target,title,content,type);
        if (StrUtils.isEmpty(target) || StrUtils.isEmpty(content) || type == null)
            return new Result(CodeEnum.FAIL_100002.getCode(),CodeEnum.FAIL_100002.getMsg());
        return lotteryServerFeignClient.jPushMsgToUser(target,title,content,type);
    }

    @ApiOperation(value = "接收极光推送结果",notes = "接收极光推送结果")
    @PostMapping("/getPushResult")
    public Result getPushResult(@ApiParam(value = "消息id",required = true) String msgIds){
        if (StrUtils.isEmpty(msgIds)){
            return new Result(CodeEnum.FAIL_100002.getCode(),CodeEnum.FAIL_100002.getMsg());
        }
        return lotteryServerFeignClient.getPushResult(msgIds);
    }
}
